package tau_sadna.tau_map;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.RelativeLayout;

@SuppressLint("NewApi")
public class OurImageView extends ImageView {
	MainActivity main;
	protected float x;
	protected float y;
	protected Drawable drawable = null;
	protected int orginalHeight;
	protected int orginalWidth;

	public OurImageView(Context context) {
		super(context);
		this.main = (MainActivity) context;
		x = -5000;
		y = -5000;
	}

	@Override
	public void setX(float x) {
		setXY(x,this.y);
	}
	
	@Override
	public void setY(float y) {
		setXY(this.x,y);
	}
	
	public void setXY(float x, float y) {
		if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB){
			super.setX(x);
			super.setY(y);
		} else {
			LayoutParams old = getLayoutParams();
			
			if(old == null){
				old = ((ViewGroup)(getParent())).generateLayoutParams(null);
			}
			
			android.view.ViewGroup.MarginLayoutParams lp = new RelativeLayout.LayoutParams(old);
			
			lp.setMargins((int)x, (int)y, -100,-100);
			this.setLayoutParams(lp);
		}
		this.x = x;
		this.y = y;
	}
	
	@Override
	public synchronized void setImageDrawable(Drawable drawable) {
		this.drawable = drawable;
		super.setImageDrawable(drawable);
	}
	
	@Override
	public void setRotation(float rotation) {
		if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
			super.setRotation(rotation);
		else{
			super.setImageDrawable(Utils.rotateDrawable(drawable, rotation));
			setX(x);
			setY(y);	
		}
	}
	
	public void setOrginalHeight(int height){
		orginalHeight = height;
	}
	
	public void setOrginalWidth(int width){
		orginalWidth = width;
	}
	
	public int getOrginalHeight(){
		return orginalHeight;
	}
	
	public int getOrginalWidth(){
		return orginalWidth;
	}
}
